package commands;

import com.amazonaws.services.s3.internal.Mimetypes;
import com.amazonaws.services.s3.model.*;
import jesss.options.JesssOptions;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import static org.mockito.Mockito.mock;

/**
 * User: Lee
 * Date: 8/22/13
 * Time: 10:29 PM
 */
public class CommandTestsBase {

    protected List<S3ObjectSummary> makeTestS3ObjectSummaries(int numObjects, String bucketName, String prefix, String delimiter) {
        Random random = new Random();
        List<S3ObjectSummary> s3ObjectSummaries = new ArrayList<>(numObjects);
        for (int i = 0; i < numObjects; i++) {
            String key = String.format("%s%sfile%s.txt", prefix, delimiter, i);
            S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
            s3ObjectSummary.setKey(key);
            s3ObjectSummary.setBucketName(bucketName);
            s3ObjectSummary.setETag(key);
            s3ObjectSummary.setLastModified(new Date());
            s3ObjectSummary.setSize(Math.abs(random.nextLong()));

            s3ObjectSummaries.add(s3ObjectSummary);
        }
        return s3ObjectSummaries;
    }

    protected  List<Bucket> makeTestBuckets(int numBuckets) {
        List<Bucket> buckets = new ArrayList<>(numBuckets);
        for (int i = 0; i < numBuckets; i++) {
            Bucket bucket = new Bucket();
            bucket.setCreationDate(new Date());
            bucket.setName(String.format("mybucket%s", i));
            bucket.setOwner(new Owner(String.format("ID%s",i), String.format("Owner%s",i)));
            buckets.add(bucket);
        }
        return buckets;
    }


    protected ObjectMetadata makeTestObjectMetadata() {
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setLastModified(new Date());
        objectMetadata.setContentType("Text");
        objectMetadata.setContentEncoding("UTF-8");
        objectMetadata.setCacheControl("None");
        objectMetadata.setContentMD5("AB912C392F321AE");
        objectMetadata.setContentLength(1_234_232);
        objectMetadata.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
        return objectMetadata;
    }

    protected CopyObjectResult makeCopyObjectResult() {
        CopyObjectResult copyObjectResult = new CopyObjectResult();
        copyObjectResult.setETag("SomeETag");
        copyObjectResult.setExpirationTime(new java.util.Date());
        copyObjectResult.setLastModifiedDate(new Date());
        return copyObjectResult;
    }
}
